package com.train.pay.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(path = {"/pay"})
public class PayController {

    @Value("${spring.application.name}")
    private String value;

    @Resource
    private DiscoveryClient discoveryClient;

    @Autowired
    RestTemplate restTemplate;

    public static final String ORDER_URL = "http://ORDER-SERVER";

    @RequestMapping(method = {RequestMethod.GET})
    public Object hi(){
        List<String> services = discoveryClient.getServices();
        services.forEach(i-> System.out.println(i));
        return "this is "+value;
    }

    @RequestMapping(path = {"/ribbon"},method = {RequestMethod.GET})
    public Object ribbonServer(){
        String result = restTemplate.getForObject("http://ORDER-SERVER/order",String.class);
        return result;
    }

    @RequestMapping(path = {"/feign"},method = {RequestMethod.GET})
    public Object feignTrain(){
        return null;
    }
}
